
#include "UdpClient.h"

UdpClient::UdpClient(QObject *parent) :
	QObject(parent)
{
	mUdpSocket = new QUdpSocket(this);
}

UdpClient::~UdpClient()
{

}

void UdpClient::OnStart(void)
{
	bind_port();
}

void UdpClient::readPendingDatagrams(void)
{
	while (mUdpSocket->hasPendingDatagrams())
	{
		QNetworkDatagram datagram = mUdpSocket->receiveDatagram();
		emit socket_receive(datagram.data());
	}
}

void UdpClient::bind_port(void)
{
	mUdpSocket->bind(QHostAddress::LocalHost, 7755);

	connect(mUdpSocket, &QUdpSocket::readyRead,
			this, &UdpClient::readPendingDatagrams);
}

